<?php

namespace app\admin\model\miniapp;

use think\Model;


class Version extends Model
{

    

    

    // 表名
    protected $name = 'wechat_miniapp_version';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'audit_status_text',
        'succ_time_text',
        'fail_time_text'
    ];
    

    
    public function getStatusList()
    {
        return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getAuditStatusList()
    {
        return ['-1' => __('Audit_status -1'), '0' => __('Audit_status 0'), '1' => __('Audit_status 1'), '2' => __('Audit_status 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuditStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['audit_status']) ? $data['audit_status'] : '');
        $list = $this->getAuditStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSuccTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['succ_time']) ? $data['succ_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getFailTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['fail_time']) ? $data['fail_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setSuccTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setFailTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
